package se.webbzon.boltzmann.menu;

import java.awt.image.ImageObserver;

import se.webbzon.boltzmann.configuration.Graphics;

public class EffectPage extends MFlowPage {
	
	/*============================================================
	Constructors
	============================================================*/

	public EffectPage(ImageObserver observer, AbstractGameMenuLayout layout, MPage parent) {
		super(observer, layout.getPageLayout(),parent,"Effects");
		addItem(new PageLabel(observer, layout.getLabelLayout(),this));
		addRow(0.25);
		addItem(new ReturnButton(observer, layout.getButtonLayout(), parent));
		addRow();
		addItem(new ShadowButton(layout.getButtonLayout()));
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public void onEnter(GameMenu menu) {}

	@Override public void onLeave(GameMenu menu) {}
	
	/*============================================================
	Private Methods
	============================================================*/
	
	/** Converts a boolean expression to the string "On" and "Off". **/
	private String boolToString(boolean bool) {
		if (bool)
			return "On";
		else
			return "Off";
	}
	
	/*============================================================
	Private Classes
	============================================================*/
	
	private final class ShadowButton extends MButton {

		public ShadowButton(ButtonLayout layout) {
			super(getImageObserver(), layout, false, "Shadows: " + boolToString(Graphics.instance().hasShadows()));
		}

		@Override public void onClick(GameMenu menu) {
			Graphics.instance().setShadows(!Graphics.instance().hasShadows());
			setText("Shadows: " + boolToString(Graphics.instance().hasShadows()));
		}
		
	}

}
